--[[
战斗结算数据模型
]]
local FightAccount = class("FightAccount")




function FightAccount:ctor(model)
	self.model_ = model;
	
	--0规定时间内达到某个分数，1将种道具移动到下层 2收集特定宝石，
	self.levelConditionType_ = self.model_.levelData_.levelConditionType;
    self.levelConditionParam1_ = self.model_.levelData_.levelConditionParam1;
    self.levelConditionParam2_ = self.model_.levelData_.levelConditionParam2;
    self.energyFullNums_ = self.model_.levelData_.energyFullNums;--总能量值（次数）  表示多少个每一圈的能量值
    self.energyNums_ = self.model_.levelData_.energyNums;--重新开始每一轮的能量值        秒
	self.time_ =  os.time();
	
    --记录积分数据
    self.destoryCards_ = 0;--当前销毁的卡片个数
    self.stepNums_ = 0;--当前走动的个数
    
    self.m_currentEnergys_ = 0;--当前能量
    self.m_currentEnergyFullNums_ = 0;--当前总能量值（次数）  表示多少个每一圈的能量值
    self.m_energysFull_ = false;
    self.m_dt_ = 0;
    
    
    
    
    
    --这里检验  关卡是否通关
    GameCoreManager:addEventListener(EventConstants.CurrentEnergysFull,handler(self,self.checkWin));
    GameCoreManager:addEventListener(EventConstants.EliminateAll,handler(self,self.checkWin))
end




function FightAccount:checkWin()
	if self.levelConditionType_ == 1 then --1规定时间内达到某个分数，2将种道具移动到下层  3收集特定宝石， 
		if self.destoryCards_ > self.levelConditionParam1_ 	then
	 		GameCoreManager:dispatchEvent({name=EventConstants.Victory,data = nil })
	 			
	 	elseif self.energyFullNums_ <=  self.m_currentEnergyFullNums_ then
	 		GameCoreManager:dispatchEvent({name=EventConstants.Faile,data = nil })
 		end
 	elseif self.levelConditionType_ == 2 then
 		local model = self.model_;
 		for y = 1,self.levelConditionParam2_,1 do  --y遍历
     		for x = 1,model.row_,1 do  --x遍历
				local id = "static:"..x.."_"..y;
				local obj = model:getObject(id);
				local cardSpriteId = obj:getCardSpriteId();
				if cardSpriteId == self.levelConditionParam1_ then
					GameCoreManager:dispatchEvent({name=EventConstants.Victory,data = nil })
					return
				end
     		end
 		end
 	
 	elseif self.levelConditionType_ == 3 then
 	
 	end
end





--增加或者减少N秒游戏总时间。
function FightAccount:setEnergyFullNums(count)
	count = count or 0 ;
	self.energyFullNums_ = self.energyFullNums_ + count
end




function FightAccount:addStepNums(count)
	count =  count  or 1;
    self.stepNums_ = self.stepNums_ + count;
    
    --触发一个步数改变事件
    GameCoreManager:dispatchEvent({name=EventConstants.StepNums,data = self.stepNums_ })
end


--销毁的卡牌个数
function FightAccount:addDestoryCards(count)
	count = count or 0;
    self.destoryCards_ =  self.destoryCards_ + count;
    
    --触发一个销毁的卡片个数改变事件
    GameCoreManager:dispatchEvent({name=EventConstants.DestoryCards,data =self.destoryCards_ })
end

--当前能量条变化
function FightAccount:addCurrentEnergys(count)
	count =  count  or 1;
    self.m_currentEnergys_ = self.m_currentEnergys_ + count;
    
    if self.m_currentEnergys_  > self.energyNums_ and not self.m_energysFull_ then 
    	self.m_energysFull_ = true;
    	self.m_currentEnergyFullNums_ = self.m_currentEnergyFullNums_ + 1;
    	GameCoreManager:dispatchEvent({name=EventConstants.CurrentEnergysFull,data = self.m_currentEnergys_ })
    end
    
    --触发一个能量条改变事件
    GameCoreManager:dispatchEvent({name=EventConstants.CurrentEnergys,data = self.m_currentEnergys_ })
end





function FightAccount:tick(dt)
	if not self.m_energysFull_ then
		self.m_dt_ = self.m_dt_ + dt;
		if self.m_dt_>1 then
			self:addCurrentEnergys();
			
			self.m_dt_ = 0;
		end
	end
end

return FightAccount
